package com.espirit.weixin.core;

import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.annotate.JsonProperty;

public class JsApiTicket {

	private String ticket;
	
	@JsonProperty("expires_in")
	private int expiresIn;
	
	@JsonIgnore
	private long createTime;
	
	private String errcode;
	
	private String errmsg;
	
	public JsApiTicket() {
		this.createTime = System.currentTimeMillis();
	}

	public String getTicket() {
		return ticket;
	}

	public void setTicket(String ticket) {
		this.ticket = ticket;
	}

	@JsonIgnore
	public int getExpiresIn() {
		return expiresIn;
	}

	@JsonIgnore
	public void setExpiresIn(int expireTime) {
		this.expiresIn = expireTime;
	}

	public long getCreateTime() {
		return createTime;
	}

	public void setCreateTime(long createTime) {
		this.createTime = createTime;
	}
	
	public String getErrcode() {
		return errcode;
	}

	public void setErrcode(String errcode) {
		this.errcode = errcode;
	}

	public String getErrmsg() {
		return errmsg;
	}

	public void setErrmsg(String errmsg) {
		this.errmsg = errmsg;
	}

	public boolean isExpired() {
		long gap = System.currentTimeMillis() - createTime;
		long gapSecond = gap / 1000 + 60;		// 60 -- 提前1分钟
		if (gapSecond > expiresIn) {
			return true;
		} else {
			return false;
		}
	}
}
